package com.zhubayi.controller;

import com.zhubayi.constant.MyConstant;
import com.zhubayi.entity.R;
import com.zhubayi.entity.User;
import com.zhubayi.entity.vo.HistoryVo;
import com.zhubayi.service.HistoryService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 祝八一
 */
@Controller
@RequestMapping("history")
public class HistoryController {
    @Autowired
    HistoryService historyService;
    @ResponseBody
    @GetMapping("del/{id}")
    public R del(HttpServletRequest request, Model model, @PathVariable("id") Integer id){
        HttpSession session = request.getSession();
        User user =(User) session.getAttribute("user");
        if (user==null){
            //没有登录
            return new R(MyConstant.AUTHENTICATION);
        }
        historyService.delete(user.getId(),id);
        List<HistoryVo> videos= historyService.queryByUid(user.getId());
        System.out.println(videos);
        model.addAttribute("type","MyHistory");
        model.addAttribute("videos",videos);
        return new R(MyConstant.OK);
    }
}
